class: title-slide, right, top background-image: url(data:image/png;base64,#img/fog.png) background-position: 90% 75%, 75% 75% background-size:cover .left-column[ # NHS Workshop<br>Introduction to ggplot ] .right-column[ ### fonts and themes **Eugene Hickey**<br> January 21st 2021 ] .palegrey[.left[.footnote[Graphic by [Elaine Hickey](https://photos.google.com/photo/AF1QipMjKNoaxyne8nte4HmxA6Th9-4fUfSbl_mx-_1G)]]] ??? Welcome to the workshop on ggplot. Where we'll show you how to create impressive data visualisations. --- layout: true <a class="footer-link" href="http://intro-ggplot-nhs.netlify.app">intro-ggplot-nhs — Eugene Hickey</a> <!-- this adds the link footer to all slides, depends on footer-link class in css--> --- class: center, inverse # <p style="font-family:'Cabin Sketch'">Using Themes in R</p> <br> ### We'll also discuss fonts (first) and scales. - themes give fine control to the appearance of your plots - control over text size, fonts, text colour, etc - position of legends, titles, captions, etc - colours of backgrounds - delete unwanted features (like, say, tick marks on an axis) --- class: center, inverse - large number of preset themes - the _Wall Street Journal_ theme we used in assignment two - several packages with neat bundle of useful themes - and, of course, we can develop our own theme to have consistent graphics --- ## Fonts - we'll discuss this first, as often themes require fonts which might not be present - fonts are a whole world of their own - see [practicaltypography.com](practicaltypography.com) - great talk by [Will Chase](https://rstudio.com/resources/rstudioconf-2020/the-glamour-of-graphics/) at RStudioConf2020 --- - need to be in the system, load them into windows / mac / linux - only really works for true type fonts (.ttf) - go to folder where the R library lives and seek out fonts - type **.libPaths()** to find out where - e.g. R/x86_64-pc/3.6/tvthemes/fonts/SpongeBob - click on .ttf files to install --- - then need to capture them in R - install package *extrafont* - run *ttf_import()* with path = folder from above - run *View(fonttable())* to check available fonts - usually need to restart R (*Session* then *Restart R*) --- - can also use the *showtext* package - use _font_add()_ function - then _showtext_auto()_ --- - can also use google fonts using the *showtext* package <!-- --> - type *font_info_google()* to find them --- ## Complete Themes - these set up ggplots with standard appearances - can always adjust these, but do so in a layer after invoking the theme - some defaults in ggplot2, see [here](https://ggplot2.tidyverse.org/reference/ggtheme.html) - you should experiment with these to see how they look --- .pull-left[ <!-- --> ] .pull-right[ <!-- --> ] --- ## Complete Themes - other package provide supplementary themes - *ggthemes* - *ggthemr* (see [here](https://github.com/cttobin/ggthemr)) - *tvthemes* (see [here](https://ryo-n7.github.io/2019-05-16-introducing-tvthemes-package/)) - *hrbrthemes* see [here](https://github.com/hrbrmstr/hrbrthemes) - *firatheme* (see [here](https://github.com/vankesteren/firatheme)) - *bbplot*, themes from the BBC (see [here](https://github.com/bbc/bbplot)) - *ggtech* themes from companies, e.g. Facebook. See [here](https://github.com/ricardo-bion/ggtech) --- - [This website](https://rfortherestofus.com/2019/08/themes-to-improve-your-ggplot-figures/) is pretty good on themes - again, make sure you experiment with these --- ## Fine Control Over Themes - we can change any feature of a theme that we want - type *?theme* on the console to see available themes - use *element_&&&&&* to replace theme - example: *theme(text = element_text(family = "Roboto Sans"))* --- <!-- --> --- <!-- --> --- - **theme_set()** and **theme_get()** pretty useful <!-- --> --- <!-- --> --- class: center, inverse # _scales_ - I like the scales package and feel it's worth discussing - We used it to give dollar signs in the last assignment - (also, has the _show_col()_ function) - can be used to change to scientific notation, or not - utilities like _comma()_, _dollar()_, _label_number_si()_, _percent()_, _pretty_breaks()_ - [this is a nice overview](https://bookdown.org/Maxine/ggplot2-maps/posts/2019-11-27-using-scales-package-to-modify-ggplot2-scale/) --- <!-- -->